#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Sun May 26 11:08:21 2013

@author: Sat Kumar Tomer
@email: satkumartomer@gmail.com
@website: www.ambhas.com
"""


import numpy as np
from ambhas.interpolation import idw
import matplotlib.pyplot as plt
import os

# outfile paths
image_location_gauge_idw = '../images/rain_location_gauge_idw.png'
image_idw_rain1 = '../images/rain_idw1.png'
image_idw_rain2 = '../images/rain_idw2.png'

# convert relative path into absolute 
cur_dir = os.path.dirname(__file__)
image_location_gauge_idw = os.path.join(cur_dir, image_location_gauge_idw)
image_idw_rain1 = os.path.join(cur_dir, image_idw_rain1)
image_idw_rain2 = os.path.join(cur_dir, image_idw_rain2)

# generate some synthetic data
x = np.random.random(10) 
y = np.random.random(10)
X = np.linspace(0, 1, 200)
Y = np.linspace(0, 1, 200)
rain = np.random.random(10)
rain[np.random.permutation(10)[:4]] = 0

# interpolate using IDW
data = idw(x, y, rain, X, Y)

# plot the gauge rainfall
plt.clf()
plt.scatter(x,y, c=rain, marker='s', linewidths=0, vmax=1)
plt.xlabel('X')
plt.ylabel('Y')
plt.colorbar()
plt.savefig(image_location_gauge_idw)
plt.close()

# plot the interpolated data
plt.clf()
plt.pcolor(X,Y,data, vmin=0, vmax=1)
plt.plot(x,y, '*')
plt.xlabel('X')
plt.ylabel('Y')
plt.colorbar()
plt.savefig(image_idw_rain1)
plt.close()

# interpolate using IDW 
data = idw(x, y, rain, X, Y, rainfall=True)

# plot the interpolated data
plt.clf()
plt.pcolor(X,Y,data, vmin=0, vmax=1)
plt.plot(x,y, '*')
plt.xlabel('X')
plt.ylabel('Y')
plt.colorbar()
plt.savefig(image_idw_rain2)
plt.close()



